home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BBS in a Box 7
/
BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso
/
Files
/
Prog
/
D-G
/
DA Skeleton 2.0.cpt
/
MiscRoutines.p
< prev
Wrap
Text File
|
1990-06-02
|
3KB
|
137 lines
unit MiscRoutines;
interface
uses
Globals;
{This function figures out the resource id's for our DA. See Inside Mac}
{for more information on converting resource id's for DA's. "refNum"}
{ is set in the open routine and is located in the unit 'Globals'.}
function rslvid (id: integer): integer;
{This gets the screen size. When ever a new port is created, its initial}
{size is equal to the screenBits.bounds. We need to do this since we}
{cannot use QuickDraw globals from drivers.}
function GetScrSize: Rect;
{FlashDItem will flash a button in a dialog. It is intended for when a user}
{presses the return or enter key to exit the dialog.}
procedure FlashDItem (dp: DialogPtr; item: integer);
{UpdateFilter can be used as a filter to ModalDialog. It will automatically}
{put a ring around the default button and update it if it ever get covered}
{up. It captures the return and enter keys as a item 1 hit.}
function UpdateFilter (theDialog: DialogPtr; var event: EventRecord; var itemHit: integer): Boolean;
{CenterWindow will center dialogs or windows on the screen. Horz and}
{Vert specify if the window should be centered horizontally or Verically}
procedure CenterWindow (win: WindowPtr; Horz, Vert: Boolean);
implementation
{--------------------------------•--------------------------------}
function rslvid;
var
refNum: integer;
begin
refNum := Abs(-dce^.dCtlRefNum) - 1;
rslvid := BitOr($C000, BSL(refNum, 5)) + id;
end;
{--------------------------------•--------------------------------}
function GetScrSize;
var
aPort: GrafPtr;
begin
aPort := GrafPtr(NewPtr(SIZEOF(GrafPort)));
OpenPort(aPort);
GetScrSize := aPort^.portBits.bounds;
ClosePort(aPort);
DisposPtr(Ptr(aPort));
end;
{--------------------------------•--------------------------------}
procedure FlashDItem;
var
tickScratch: longint;
itype: integer;
ihan: Handle;
irect: Rect;
begin
GetDItem(dp, item, itype, ihan, irect);
HiliteControl(ControlHandle(ihan), 1);
Delay(6, tickScratch);
end;
{--------------------------------•--------------------------------}
function UpdateFilter;
var
chCode: integer;
itype: integer;
ihan: Handle;
irect: Rect;
begin
SetUpA4;
UpdateFilter := False;
case event.what of
keyDown:
begin
chCode := BitAnd(event.message, charCodeMask);
if (chCode = 13) or (chCode = 3) then
begin
itemHit := 1;
FlashDItem(theDialog, itemHit);
UpdateFilter := True;
end;
end;
mouseDown:
;
UpdateEvt:
begin
GetDItem(theDialog, 1, itype, ihan, irect);
InsetRect(irect, -4, -4);
PenSize(3, 3);
FrameRoundRect(irect, 16, 16);
PenSize(1, 1);
end;
end;
RestoreA4;
end;
{--------------------------------•--------------------------------}
procedure CenterWindow;
var
h, v: integer;
begin
if (Horz) then
h := (screenBounds.right - (win^.portRect.right - win^.portRect.left)) div 2
else
h := -win^.portBits.bounds.left;
if (Vert) then
begin
v := (screenBounds.bottom - (win^.portRect.bottom - win^.portRect.top)) div 2;
if (screenBounds.bottom > 500) then
v := v - 200;
end
else
v := -win^.portBits.bounds.top;
MoveWindow(win, h, v, True);
end;
{--------------------------------•--------------------------------}
end.